package com.sun.module_base.ext.lifecycle

import android.os.Handler
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner

/**
 *@author:sunc
 *@time :2025/7/21 10:43
 *@desc: 描述
 */
class KtxHandler(lifecycleOwner: LifecycleOwner, callback: Callback) : Handler(callback),
    DefaultLifecycleObserver {

    private val mLifecycleOwner: LifecycleOwner = lifecycleOwner

    init {
        lifecycleOwner.lifecycle.addObserver(this)
    }

    override fun onDestroy(owner: LifecycleOwner) {
        super.onDestroy(owner)
        removeCallbacksAndMessages(null)
        mLifecycleOwner.lifecycle.removeObserver(this)
    }


}